package com.liliya.servlet.cate;

import com.liliya.pojo.SubCate;
import com.liliya.service.impl.SubCateServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description TODO
 * @Author hhy
 * @Date 2021/1/12 20:50
 */
@WebServlet(urlPatterns = "/subcate/manage")
public class SubCateManage extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int num = 1;
        String catenum = req.getParameter("catenum");
        if (catenum != null) {
            req.setAttribute("catenum", catenum);
        } else {
            catenum = (String) req.getAttribute("catenum");
        }
        String p = req.getParameter("p");
        req.setAttribute("catenum", catenum);
        if (p != null) {
            num = Integer.parseInt(p);
        }
        SubCateServiceImpl subCateService = new SubCateServiceImpl();
        int total = subCateService.totalSubCate();
        int step = 5;
        int start = (num - 1) * step + 1;
        int end = start + step;
        List<SubCate> subCates = subCateService.findSubCate(start, end, Integer.parseInt(catenum));
        req.setAttribute("subcates",subCates);
        req.getRequestDispatcher("../cate/subcatemanage.jsp").forward(req,resp);
    }
}
